package org.mspring.mlog.dao.impl;

import java.util.List;

import org.mspring.mlog.dao.LinkDao;
import org.mspring.mlog.entity.Link;
import org.mspring.platform.dao.hibernate.GenericDao;
import org.springframework.stereotype.Repository;

/**
 *
 * @author Gao Youbo
 * @since 2014-01-11
 */
@Repository
public class LinkDaoImpl extends GenericDao<Link, Long> implements LinkDao {

    @Override
    public List<Link> listVisableLinks() {
        return list("select link from Link link where link.visable = true order by link.sort asc");
    }

    @Override
    public List<Link> listVisableLinks(long linkType) {
        String queryString = "select link from Link link where link.visable = true and link.type.id = ? order by link.sort asc";
        return list(queryString, linkType);
    }

    @Override
    public void updateLinkVisable(long id, boolean visable) {
        executeUpdate("update Link l set l.visable = ? where l.id = ?", visable, id);
    }

    @Override
    public void updateLinkSort(long id, long sort) {
        executeUpdate("update Link l set l.sort = ? where l.id = ?", sort, id);
    }

}
